package org.springcloud.wisdom.spring_02_classroom.teacher.records.dao;

import org.apache.ibatis.annotations.*;
import org.springcloud.wisdom.spring_02_classroom.teacher.records.entity.RecordsEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RecordsDao {

    //发起签到
    @Insert("insert into records(id, did, sid, stu,cid,tid,signtime)" +
            "VALUES (#{id},#{did},#{sid},#{stu},#{cid},#{tid},#{signtime})")
    int insertRecords(RecordsEntity recordsEntity);

    //签到
    @Update("UPDATE records " +
            "SET stu=1, reacttime=#{reacttime} " +
            "WHERE id=#{id}")
    int updateRecords(RecordsEntity recordsEntity);

    // 签到记录
    // 根据学生学号查询自己的签到记录
    @Select("SELECT " +
            "r.*, " +
            "t.tname, " +
            "c.cname " +
            "FROM records r " +
            "INNER JOIN teacher t ON r.tid = t.tid " +
            "INNER JOIN course c ON r.cid = c.cid " +
            "WHERE r.sid = #{sid} " +
            "ORDER BY r.signtime DESC " +
            "LIMIT #{start}, #{size}")
    List<RecordsEntity> get(@Param("sid") String sid, int start, int size);
    @Select("<script>" +
            "SELECT count(*) FROM records " +
            "WHERE sid = #{sid} " +
            "</script>")
    public int Counts( String sid);



}
